//
//  RSConfirmViewController.m
//  iAccountBook
//
//  Created by 侯伟 on 2020/1/13.
//  Copyright © 2020 侯伟. All rights reserved.
//

#import "RSConfirmViewController.h"

@interface RSConfirmViewController ()

/// 标题
@property (nonatomic,strong) UILabel *titleLb;

/// 内容
@property (nonatomic,strong) UILabel *messageLb;

@end

@implementation RSConfirmViewController

- (void)loadView{
    [super loadView];
    [self initViews];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)initViews{

    
    MyLinearLayout* popView = [[MyLinearLayout alloc] initWithOrientation:(MyOrientation_Vert)];
    popView.backgroundColor = UIColor.whiteColor;
    popView.myHorzMargin = PX(37.5);
    popView.myCenterY = -40;
    popView.myHeight = MyLayoutSize.wrap;
    [self.view addSubview:popView];
    self.popView = popView;
    
    UILabel* titleLb = [UILabel lableWithFont:FONTBOLD_FIT(18) color:COLOR_BLACK_DARK text:self.titleStr];
    titleLb.textAlignment = NSTextAlignmentCenter;
    titleLb.numberOfLines = 0;
    titleLb.myHorzMargin = 15.0;
    titleLb.myTop = 24;
    titleLb.myHeight = MyLayoutSize.wrap;
    [popView addSubview:titleLb];
    _titleLb = titleLb;
    
    
    UILabel* messageLb = [UILabel lableWithFont:FONT_FIT(15) color:COLOR_BLACK_DARK text:self.messageStr];
    messageLb.textAlignment = NSTextAlignmentCenter;
    messageLb.myHorzMargin = 15.0;
    messageLb.myTop = 16;
    messageLb.numberOfLines = 0;
    messageLb.myHeight = MyLayoutSize.wrap;
    [popView addSubview:messageLb];
    _messageLb = messageLb;
    
    UIView* lineView = [UIView new];
    lineView.myHorzMargin = 0;
    lineView.myHeight = Size_1PX;
    lineView.backgroundColor = COLOR_GRAY_BASE;
    lineView.myTop = 16;
    [popView addSubview:lineView];
    
    
    MyLinearLayout* buttonLayout = [[MyLinearLayout alloc] initWithOrientation:(MyOrientation_Horz)];
    buttonLayout.padding = UIEdgeInsetsMake(0, 0, 0, 0);
    buttonLayout.myHeight = PX(44.0);
    buttonLayout.myMargin = 0;
    buttonLayout.gravity = MyGravity_Horz_Stretch|MyGravity_Vert_Fill;
    [popView addSubview:buttonLayout];
    
    UIButton* cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    if (self.cancelTitle.length) {
        [cancelBtn setTitle:self.cancelTitle forState:UIControlStateNormal];
    }else{
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    }
    
    [cancelBtn setTitleColor:COLOR_BLACK_DARK forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = FONT_FIT(15);
    [cancelBtn addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
    cancelBtn.myMargin = 0;
    [buttonLayout addSubview:cancelBtn];
    
    UIView* line = [UIView new];
    line.myMargin = 0;
    line.myWidth = Size_1PX;
    line.backgroundColor = COLOR_GRAY_LINE;
    [buttonLayout addSubview:line];
    
    UIButton* doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    if (self.confirmTitle.length) {
        [doneBtn setTitle:self.confirmTitle forState:UIControlStateNormal];
    }else{
        [doneBtn setTitle:@"确定" forState:UIControlStateNormal];
    }
    
    [doneBtn setTitleColor:COLOR_THEME forState:UIControlStateNormal];
    doneBtn.titleLabel.font = FONT_FIT(15);
    [doneBtn addTarget:self action:@selector(done:) forControlEvents:UIControlEventTouchUpInside];
    doneBtn.myMargin = 0;
    [buttonLayout addSubview:doneBtn];
}

#pragma mark - actions

- (void)done:(UIButton *)sender {
    [self dismissAlertController:^{
        if(self.confirmBlock){
            self.confirmBlock(YES);
        }
    }];
}
- (void)cancel:(UIButton *)sender {
    [self dismissAlertController:^{
        if(self.confirmBlock){
            self.confirmBlock(NO);
        }
    }];
}

@end
